#include <stdio.h>

int main(void)
{
	int day[][12]={{31,28,31,30,31,30,31,31,30,31,30,31},{31,29,31,30,31,30,31,31,30,31,30,31}};
	int year,month;
	scanf("%d%d",&year,&month);
	printf("%d\n", ((year%400)|| ((year%4==0) && (year%100!=0)))? day[1][month-1]:day[0][month-1]);
	return 0;
}
